package com.feeyo.groundservice.http.base
import com.feeyo.groundservice.base_util.FyLog
import com.feeyo.groundservice.base_util.LoadingUtil

/**
 *作者：QLH on 2023-09-19
 *描述：自定义，处理loading和异常,如果默认的不喜欢，可以自己再封装一层
 * @param msg   loading提示内容 [默认为null]
 * @param silence  是否是静默  [默认为false]
 * @param composeLoading  针对loading状态的回调 [默认为{}]
 */



abstract class BaseObserver<T>(
    private val msg: String? = null,
    private val silence: Boolean = false,
    private val composeLoading: (Boolean) -> Unit = {},
) : NetWorkObserver<T>() {


    override fun onLoadingStart() {
        if (!silence) {
            LoadingUtil.show(msg)
        }
        composeLoading(true)
        FyLog.e("onLoadingStart", "onLoadingStart")
    }

    override fun onLoadingEnd() {
        if (!silence) {
            LoadingUtil.smartClose()
        }
        composeLoading(false)
        FyLog.e("onLoadingEnd", "onLoadingEnd")
    }
}